home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 August: Tool Chest / Dev.CD Aug 00 TC Disk 2.toast / pc / sample code / quicktime / quicktime for java / qteffects / src / qteffect / controlpanel.java
Encoding:
Java Source  |  2000-06-23  |  6.3 KB  |  213 lines

  1. /*
  2.  *        quicktime.app Library
  3.  *
  4.  *        © 1996, Copyright, Apple Computer
  5.  *        All rights reserved
  6.  *
  7.  *        $Workfile:: ControlPanel.java                                                  $
  8.  *        $Archive:: /Biscotti/QTJavaDemos/QTEffects/src/qteffect/ControlPanel.java        $
  9.  *
  10.  *        Authors: Bill Stewart
  11.  */
  12. package qteffect;
  13.  
  14. import java.awt.*;
  15. import java.awt.event.*;
  16.  
  17. import quicktime.*;
  18. import quicktime.std.image.*;
  19. import quicktime.app.image.QTTransition;
  20. import quicktime.app.display.*;
  21. import PlayQTEffectApp;
  22. /**
  23.  * A simple panel of AWT objects to demonstrate how AWT can be used to control a
  24.  * QuickTime movie.
  25.  */
  26. public class ControlPanel extends Panel implements Errors {
  27. //_________________________ CLASS METHODS
  28.  
  29.     public ControlPanel (QTTransition ef, QTCanvas c) throws QTException {
  30.         this.transition = ef;
  31.         final QTCanvas cv = c;
  32.         
  33.         GridBagLayout gb = new GridBagLayout();
  34.         setLayout (gb);
  35.         setFont (new Font("Helvetica", Font.BOLD, 10));
  36.  
  37.         GridBagConstraints cons = new GridBagConstraints();
  38.         cons.fill = GridBagConstraints.HORIZONTAL;
  39.         cons.gridheight = 1;        
  40.         cons.insets = new Insets (2, 2, 2, 2);
  41.         
  42.         cons.gridx = 0;
  43.         cons.gridy = 0;
  44.         cons.gridwidth = 3;
  45.         
  46.         add (runEffectButton, cons);
  47.         
  48.         cons.gridx = 3;
  49.         add (chooseEffectButton, cons);
  50.  
  51.         cons.gridwidth = 2;
  52.         cons.gridy = 1;
  53.         cons.gridx = 0;
  54.         add (timeLabel, cons);
  55.         
  56.         cons.gridx = 2;
  57.         add (timeField, cons);
  58.         
  59.         cons.gridx = 4;
  60.         add (timeButton, cons);
  61.  
  62.         cons.gridy = 2;
  63.         cons.gridx = 0;
  64.         add (frameLabel, cons);
  65.         
  66.         cons.gridx = 2;
  67.         add (frameField, cons);
  68.         
  69.         cons.gridx = 4;
  70.         add (frameButton, cons);
  71.  
  72.         cons.gridy = 3;
  73.         cons.gridx = 0;
  74.         add (fpsLabel, cons);
  75.         
  76.         cons.gridx = 2;
  77.         add (fpsField, cons);
  78.         
  79.         timeField.addActionListener (new ActionListener () {
  80.                 public void actionPerformed (ActionEvent event) {
  81.                     String str = new String (event.getActionCommand());
  82.                     String output = "";
  83.                     for (int i = 0; i < str.length(); i++) {
  84.                         if (Character.isDigit (str.charAt (i)))
  85.                             output += str.charAt (i);
  86.                         else
  87.                             break;
  88.                     }
  89.                     try {
  90.                         transition.setTime (new Integer (output).intValue());
  91.                         timeField.setText (Integer.toString (transition.getTime()));
  92.                         frameField.setText (Integer.toString (transition.getFrames()));
  93.                     } catch (QTException e) {
  94.                         e.printStackTrace();
  95.                     }
  96.                 }
  97.             });
  98.         frameField.addActionListener (new ActionListener () {
  99.                 public void actionPerformed (ActionEvent event) {
  100.                     String str = new String (event.getActionCommand());
  101.                     String output = "";
  102.                     for (int i = 0; i < str.length(); i++) {
  103.                         if (Character.isDigit (str.charAt (i)))
  104.                             output += str.charAt (i);
  105.                         else
  106.                             break;
  107.                     }
  108.                     try {
  109.                         transition.setFrames (new Integer (output).intValue());
  110.                         timeField.setText (Integer.toString (transition.getTime()));
  111.                         frameField.setText (Integer.toString (transition.getFrames()));
  112.                     } catch (QTException e) {
  113.                         e.printStackTrace();
  114.                     }
  115.                 }
  116.             });
  117.         fpsField.addActionListener (new ActionListener () {
  118.                 public void actionPerformed (ActionEvent event) {
  119.                     String str = new String (event.getActionCommand());
  120.                     String output = "";
  121.                     for (int i = 0; i < str.length(); i++) {
  122.                         if (Character.isDigit (str.charAt (i)))
  123.                             output += str.charAt (i);
  124.                         else
  125.                             break;
  126.                     }
  127.                     try {
  128.                         transition.setFramesPerSecond (new Integer (output).intValue());
  129.                         frameField.setText (Integer.toString (transition.getFrames()));
  130.                     } catch (QTException e) {
  131.                         e.printStackTrace();
  132.                     }
  133.                 }
  134.             });
  135.         runEffectButton.addActionListener (new ActionListener () {                
  136.                 public void actionPerformed (ActionEvent event) {
  137.                     try {
  138.                         transition.doTransition();
  139.                         if (transition.isProfiled()) {
  140.                             String profileString = "Transition Profile:"
  141.                                 + "requestedDuration:" + transition.getTime()
  142.                                 + ",actualDuration:" + transition.profileDuration()
  143.                                 + ",requestedFrames:" + transition.getFrames()
  144.                                 + ",framesRendered=" + transition.profileFramesRendered()
  145.                                 + ",averageRenderTimePerFrame=" + (transition.profileDuration() / transition.profileFramesRendered());
  146.                             System.out.println (profileString);
  147.                         }
  148.                             
  149.                     } catch (QTException e) {
  150.                         if (e.errorCode() != userCanceledErr)
  151.                             e.printStackTrace();
  152.                     }
  153.                 }
  154.             });
  155.         chooseEffectButton.addActionListener (new ActionListener () {
  156.                 public void actionPerformed (ActionEvent event) {
  157.                     try {
  158.                         PlayQTEffectApp.showDialog (transition);
  159.                     } catch (QTException e) {
  160.                         if (e.errorCode() != userCanceledErr)
  161.                             e.printStackTrace();
  162.                     }
  163.                 }
  164.  
  165.             });
  166.  
  167.         frameButton.addItemListener (new ItemListener () {
  168.                 public void itemStateChanged (ItemEvent event) {
  169.                     transition.doTime (false);
  170.                 }
  171.             });        
  172.         timeButton.addItemListener (new ItemListener () {
  173.                 public void itemStateChanged (ItemEvent event) {
  174.                     transition.doTime (true);
  175.                 }
  176.             });    
  177.     
  178.         timeField.setText (Integer.toString (transition.getTime()));
  179.         frameField.setText (Integer.toString (transition.getFrames()));
  180.         fpsField.setText (Integer.toString (transition.getFramesPerSecond()));
  181.     }
  182.  
  183. //_________________________ INSTANCE VARIABLES
  184.     private Button runEffectButton = new Button("Run Effect");
  185.     private Button chooseEffectButton = new Button("Choose Effect");
  186.  
  187.     private Label timeLabel = new Label ("Effect Length (msecs):", Label.RIGHT);
  188.     private TextField timeField = new TextField (8);
  189.  
  190.     private Label frameLabel = new Label ("Total Frames:", Label.RIGHT);
  191.     private TextField frameField = new TextField (8);
  192.  
  193.     private Label fpsLabel = new Label ("Frames Per Second:", Label.RIGHT);
  194.     private TextField fpsField = new TextField (8);
  195.     
  196.     private CheckboxGroup cbg = new CheckboxGroup ();
  197.     private Checkbox timeButton = new Checkbox ("Time", cbg, true);
  198.     private Checkbox frameButton = new Checkbox ("Frames", cbg, false);
  199.     
  200.     private QTTransition transition;
  201.     
  202. //_________________________ INSTANCE METHODS
  203.     /**
  204.      * @return a Dimension object which defines the minimum size
  205.      */     
  206.     public Dimension getMinimumSize() { return new Dimension (0, 100); }
  207.  
  208.     /**
  209.      * @return a Dimension object which defines the preferred size
  210.      */     
  211.     public Dimension getPreferredSize() { return getMinimumSize(); }
  212. }
  213.